package com.dormitory.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dormitory.manage.mapper.CommentMapper;
import com.dormitory.manage.pojo.Comment;
import com.dormitory.manage.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Date;
import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description CommentServiceImpl
 * @date 2023/4/21 0021 9:36
 */
@Service
@Slf4j
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    @Override
    public List<Comment> getAll() {
        return this.baseMapper.selectList(new QueryWrapper<Comment>().orderByDesc("create_time"));
    }

    @Override
    public boolean addComment(Comment comment) {
//        Comment content = this.baseMapper.selectOne(new QueryWrapper<Comment>().eq("content", comment.getContent()).eq("username",comment.getUsername()));
//        if (null != content)    return false;
        comment.setCreateTime(new Date());
        comment.setAvatar("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        return this.baseMapper.insert(comment) > 0;
    }

    @Override
    public boolean updateCompleted(Long id) {
        Comment comment = this.baseMapper.selectById(id);
        comment.setIsCompleted(1);
        return this.baseMapper.updateById(comment) > 0;
    }
    @Override
    public boolean deleteComment(Long id) {
       return this.baseMapper.deleteById(id) > 0;
    }
}
